from sklearn import svm
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score


if __name__ == '__main__':
    iris=load_iris()
    n_samples,n_features=iris.data.shape

    #划分测试集、训练集
    train_data,test_data=train_test_split(iris.data,random_state=1,train_size=0.7,test_size=0.3)#random_state是随机种子,上下两个种子一样
    train_label,test_label=train_test_split(iris.target,random_state=1,train_size=0.7,test_size=0.3)

    classifier=svm.SVC(C=2,kernel='rbf',gamma=10,decision_function_shape='ovr')#高斯核函数
    classifier.fit(train_data,train_label.ravel())
    pre_train=classifier.predict(train_data)
    pre_test=classifier.predict(test_data)
    print("train: ",accuracy_score(train_label,pre_train))
    print("test: ",accuracy_score(test_label,pre_test))